import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * Write a description of class Magnetica here.
 * 
 * @author (Faco Fernando Gosch Acosta) 
 * @version (1.0)
 */
public class Magnetica extends Armas
{
    protected SimpleTimer gravita;
    protected int lapsoGravita;
    
    /**
     * Magnetica Constructor inicia los valores de magnetica
     *
     * @param unGrado el grado al cual se colocara el arma
     */
    public Magnetica(int unGrado)
    {
        super(100,unGrado);
        gravita = new SimpleTimer();
        gravita.mark();
        lapsoGravita = 200;
    }
    
    /**
     * Act - do whatever the Magnetica wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    public void act() 
    {
        Pulido p = (Pulido) getOneIntersectingObject(Pulido.class);
        Grande g = (Grande) getOneIntersectingObject(Grande.class);
        Metal m = (Metal) getOneIntersectingObject(Metal.class);
        Pequenio pe = (Pequenio) getOneIntersectingObject(Pequenio.class);
        
        if(p!=null){
            chocaP(p);
        }
        
        else if(g!=null){
            quitaVida(g.dameDanio());
        }
        
        else if(m!=null){
           m.setRotation(m.getRotation() + 180);
        }
        
        else if(pe!=null){
            quitaVida(pe.dameDanio());
        }       
        
        if(gravita.millisElapsed() > lapsoGravita)
        {
            int angt = ((Espacio) getWorld()).dameAnguloTierra();            
            gradosPosicion = (gradosPosicion + 45) % 360;
            gravita();
            setRotation(angt);
            gravita.mark();
        }
    }    
}
